home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / GUI / GUIFront / Demos / Source / Generic.c < prev    next >
C/C++ Source or Header  |  1994-10-21  |  5KB  |  153 lines

  1.  
  2. /* This generic driver is used as a template for the demos contained in this
  3.  * directory. To build an example, compile this file and the example your're
  4.  * interested in into object files, and then link the two together.
  5.  *
  6.  * Note: This code serves as a simple container for the included example GUI
  7.  * layouts. It is not intended to be a shining example of clear, well
  8.  * written C, so please excuse typecast warnings, missing comments, badly
  9.  * named variables and my blasphemic use of a ::shiver:: goto statement.
  10.  *
  11.  * 8.10.94: Added support for preferences update messages from prefs editor
  12.  */
  13.  
  14. /* Include everything */
  15.  
  16. #include <libraries/guifront.h>
  17. #include <proto/guifront.h>
  18. #include <proto/dos.h>
  19. #include <proto/exec.h>
  20.  
  21. /* Library bases */
  22.  
  23. struct Library *GUIFrontBase;
  24.  
  25. /* Imported from the demo module */
  26.  
  27. extern STRPTR DEMO_Version,
  28.               DEMO_LongDesc,
  29.               DEMO_Author,
  30.               DEMO_Date;
  31.  
  32. extern BOOL   DEMO_Backfill;
  33.  
  34. extern STRPTR DEMO_WindowTitle;
  35. extern STRPTR DEMO_AppID;
  36.  
  37. extern DEMO_InitialOrientation;
  38. extern ULONG DEMO_LayoutList[];
  39. extern GadgetSpec *DEMO_GadgetSpecList[];
  40.  
  41. /* Function prototypes */
  42.  
  43. static GUIFront *buildgui(ExtErrorData * const, GUIFrontApp * const guiapp, short const left, short const top);
  44.  
  45. /* Code */
  46.  
  47. main()
  48. {
  49.     /* Attempt to open library */
  50.  
  51.     if (GUIFrontBase = OpenLibrary(GUIFRONTNAME, GUIFRONTVERSION))
  52.     {
  53.         GUIFrontApp *guiapp;
  54.  
  55.         /* Create our application anchor structure */
  56.  
  57.         if (guiapp = GF_CreateGUIApp(DEMO_AppID,
  58.             GFA_Version,  DEMO_Version,
  59.             GFA_LongDesc, DEMO_LongDesc,
  60.             GFA_Author,   DEMO_Author,
  61.             GFA_Date,     DEMO_Date,
  62.             GFA_VisualUpdateSigBit, SIGBREAKB_CTRL_F, /* For simplicity */
  63.             TAG_DONE))
  64.         {
  65.             GUIFront *gui;
  66.             ExtErrorData exterr;
  67.             short left = -1, top = -1;
  68.  
  69.             /* Create a gui for our application */
  70.  
  71. creategui:  if (gui = buildgui(guiapp,&exterr,left,top))
  72.             {
  73.                 BOOL done = FALSE;
  74.  
  75.                 /* Process input events */
  76.  
  77.                 while (!done)
  78.                 {
  79.                     struct IntuiMessage *imsg;
  80.                     ULONG signals;
  81.  
  82.                     /* Wait for an event to occur */
  83.  
  84.                     signals = GF_Wait(guiapp,SIGBREAKF_CTRL_F);
  85.  
  86.                     if (signals & SIGBREAKF_CTRL_F) /* Update visuals? */
  87.                     {
  88.                         /* Extract current left & topedge of our GUI
  89.                          * window, so we can open it at the same
  90.                          * location.
  91.                          */
  92.  
  93.                         GF_GetGUIAttr(gui, GUI_LeftEdge, &left,
  94.                                            GUI_TopEdge,  &top,
  95.                                            TAG_DONE);
  96.  
  97.                         GF_DestroyGUI(gui);
  98.                         goto creategui;
  99.                     }
  100.  
  101.                     /* We only bother to listen for CLOSEWINDOW events.
  102.                      * Of course, in a real application, you would be
  103.                      * examining the Class field for IDCMP_GADGETUP
  104.                      * messages and act accordingly.
  105.                      */
  106.  
  107.                     while (imsg = GF_GetIMsg(guiapp))
  108.                     {
  109.                         if (imsg->Class == IDCMP_CLOSEWINDOW)
  110.                             done = TRUE;
  111.  
  112.                         GF_ReplyIMsg(imsg);
  113.                     }
  114.                 }
  115.  
  116.                 /* We're done with the GUI, so free it. GF_DestroyGUIApp
  117.                  * actually does this for us, but it still looks nicer if
  118.                  * we do it manually (I think :-)
  119.                  */
  120.  
  121.                 GF_DestroyGUI(gui);
  122.             }
  123.             else
  124.                 Printf("Unable to create GUI (Error data: %ld.%ld)\n", exterr.ee_ErrorCode, exterr.ee_ErrorData);
  125.  
  126.             /* Destroy application anchor strucuture */
  127.  
  128.             GF_DestroyGUIApp(guiapp);
  129.         }
  130.         else
  131.             PutStr("Unable to create guifront application\n");
  132.  
  133.         CloseLibrary(GUIFrontBase);
  134.     }
  135.     else
  136.         PutStr("Requires guifront.library V37+\n");
  137. }
  138.  
  139. /* (Re)create a gui for our application */
  140.  
  141. static GUIFront *buildgui(GUIFrontApp * const guiapp, ExtErrorData * const exterr, short const left, short const top)
  142. {
  143.     return (GF_CreateGUI(guiapp, DEMO_LayoutList,DEMO_GadgetSpecList,
  144.         GUI_InitialOrientation, DEMO_InitialOrientation,
  145.         GUI_Backfill,           DEMO_Backfill,
  146.         GUI_ExtendedError,      exterr,
  147.         GUI_WindowTitle,        DEMO_WindowTitle,
  148.         GUI_OpenGUI,            TRUE,
  149.         GUI_LeftEdge,            left,
  150.         GUI_TopEdge,            top,
  151.         TAG_DONE));
  152. }
  153.